package cn.anlucky.admin.generation;


import cn.anlucky.admin.generation.bean.GenerationPoBean;
import cn.anlucky.admin.generation.config.GenerationConfig;
import cn.anlucky.admin.generation.povo.GenerationPo;
import cn.anlucky.admin.generation.service.GenerationCodeService;
import cn.anlucky.admin.generation.service.impl.GenerationCodeServiceImpl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GenerationApplication {

    // 数据库连接
    public static final String DB_URL = "jdbc:mysql://127.0.0.1:3306/lucky_admin?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&allowMultiQueries=true&useSSL=false&allowPublicKeyRetrieval=true";
    public static final String DB_USER_NAME = "root";
    public static final String DB_PASSWORD = "123456";

    // 代码生成配置
    private static GenerationPo generationPo = GenerationPoBean.getGenerationPo(DB_URL, DB_USER_NAME, DB_PASSWORD);
    // 模板变量
    public static final Map<String,Object> map = new HashMap<>();

    // 包
    private static final String parentPackage = "cn.anlucky.admin";
    // 模块
    private static final String moduleName = "demo";

    public static void main(String[] args) {
        // 自定义变量
        map.put("my","自定义变量"); // 模板中使用${my}
        map.put("my2","自定义变量2"); // 模板中使用${my2}
        generationPo.setOtherTemplateParams(map);

        List<String> tableNames = new ArrayList<>();
        tableNames.add("sys_users");
        tableNames.add("sys_roles");

        GenerationCodeService generationCodeService = new GenerationCodeServiceImpl(generationPo);
        // 预览代码
        // Map<String, String> map = generationCodeService.previewCode(parentPackage, moduleName, tableNames);
        // System.out.println("map = " + map);
        // 生成代码文件
        generationCodeService.generateCode(parentPackage, moduleName, tableNames);
    }

}
